/* 

Replication syntax CPS article
"Social change and women's left vote. The role of employment, education, and marriage in the gender vote gap"

Dr. Mathilde M. van Ditmars, University of Lucerne & University of Zurich
Dr. Rosalind Shorrocks, University of Manchester
May 2024 (Stata version 18)

File 2/4. SHP Data preparation and analyses for Tables
*/

*Swiss Household Panel, 1999-2019
*Data version used: W1-21; DOI: 10.23662/FORS-DS-932-6
*see https://www.swissubase.ch/en/catalogue/studies/6097/17411/datasets/932/2032/overview

*DATASET WORKING FILE CREATION*

global datadest "DEFINE"
global output "DEFINE"
set more off

cd  "DEFINE"


*adding yearly variables for all the waves, long data file creation:

local year = 1999 // this is a macro, it has the value 1999
  
foreach y in 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 {
use idpers status?? idspou?? idhous?? plingu?? noga2m?? p??w31 is4maj?? xis4ma?? x??w03 ///
educat?? civsta?? age?? relarp?? occupa?? nat_1_?? nat_2_?? nat_3_?? p??p10 p??p19 p??p01 tr1maj?? ///
wstat?? ownkid?? gldmaj?? p??w87 p??w90 i??ptotg i??ptotn ///
using shp`y'_p_user if status`y'==0, clear
renvars status?? idspou?? idhous?? plingu?? noga2m?? is4maj?? xis4ma?? nat_1_?? nat_2_?? nat_3_?? ///
educat?? civsta?? age?? relarp?? occupa?? tr1maj?? wstat?? ownkid?? gldmaj??, postsub(`y') 
renvars p`y'* , presub(p`y' p)
renvars x`y'* , presub(x`y' x)
renvars i`y'* , presub(i`y' i)
gen year=`year' // replaces `year' with the value of the macro 
save $datadest/tempp`y', replace
      local year = `year' + 1 // changes the value of the macro
   }
  
foreach y in 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 {
use idhous?? i??dispy region?? com2_?? using shp`y'_h_user, clear
renvars i`y'* , presub(i`y' i)
renvars idhous?? region?? com2_??, postsub(`y') 
save $datadest/temph`y', replace
   } 
   
foreach y in 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19  {
use $datadest/tempp`y'
merge m:1 idhous using $datadest/temph`y', nogen
keep if status==0
save $datadest/tempp`y', replace
}
  
foreach y in 99 00 01 02 03 04 05 06 07 08 09 11 14 17 {
use idpers p??p13 p??p15 p??p17 using shp`y'_p_user, clear
renvars p`y'* , presub(p`y' p)
save $datadest/temp_prefs`y', replace
   } 
 
 
foreach y in 99 00 01 02 03 04 05 06 07 08 09 11 14 17 {
use $datadest/tempp`y'
merge 1:1 idpers using $datadest/temp_prefs`y', nogen
keep if status==0
save $datadest/tempp`y', replace
}

foreach y in 00 01 02 03 04 05 06 07 08 09 11 14 17 {
use idpers p??p20 p??p21 p??p22 using shp`y'_p_user, clear
renvars p`y'* , presub(p`y' p)
save $datadest/temp_gender`y', replace
   } 
   
foreach y in 00 01 02 03 04 05 06 07 08 09 11 14 17 {
use $datadest/tempp`y'
merge 1:1 idpers using $datadest/temp_gender`y', nogen
keep if status==0
save $datadest/tempp`y', replace
}

foreach y in 99 00 01 02 03 04 05 06 07 08 09 12 15 18 {
use idpers p??r01 p??r04 using shp`y'_p_user, clear
renvars p`y'* , presub(p`y' p)
save $datadest/temp_reli`y', replace
   }
   
foreach y in 99 00 01 02 03 04 05 06 07 08 09 12 15 18 {
use $datadest/tempp`y'
merge 1:1 idpers using $datadest/temp_reli`y', nogen
keep if status==0
save $datadest/tempp`y', replace
}

foreach y in 11 14 17 {
use idpers p??p50 p??p51 p??p52 p??p53 p??p54 p??p55 p??p56 p??p57 p??p58 p??p59 p??p60 ///
p??p61 p??p62 p??p63 p??p66 p??p67 p??p68 p??p75 using shp`y'_p_user, clear
renvars p`y'* , presub(p`y' p)
save $datadest/temp_polmodule`y', replace
   }
   
foreach y in 11 14 17 {
use $datadest/tempp`y'
merge 1:1 idpers using $datadest/temp_polmodule`y', nogen
keep if status==0
save $datadest/tempp`y', replace
   }

*append the waves
use $datadest/tempp19
foreach y in 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 99 {
      append using $datadest/tempp`y'
   }
   
save $datadest/longfile_child, replace
xtset idpers year
save $datadest/longfile_child, replace

*add social origin data
use $datadest/longfile_child
merge m:1 idpers using shp_so, keepusing(p__o13 p__o14 p__o30 p__o31 p__p47 p__p46 p__o58 p__o59 p__o34 p__o17 is4faj__ is4moj__ tr1faj__ tr1moj__ gldfaj__ gldmoj__) keep (master match)  nogen
save $datadest/longfile_child_so, replace

*add biography data 
use $datadest/longfile_child_so
merge m:1 idpers using shp0_bvfe_user, keepusing(bvfe003 bvfe004) keep (master match) nogen
save $datadest/longfile_child_so_bio, replace


*add master personal file variables
use $datadest/longfile_child_so_bio
merge m:1 idpers using shp_mp, keepusing(sex birthy idfath__ idmoth__) keep (master match) nogen
save $datadest/longfile_child_so_bio_mp, replace

xtset idpers year
save $datadest/SHP_workfile, replace


*select variables to keep and save as new dataset
keep year idpers idhous status age relarp idspou civsta educat occupa nat_1_ nat_2_ nat_3_ plingu pw31 is4maj pp01 pp10 pp19 pp13 pp17 pp63 pp61 pp20 pp21 pp22 pr04 pp50 pp51 pp52 is4faj__ p__o13 p__o14 p__o17 is4moj__ p__o30 p__o31 p__o34 birthy sex educ_level class16_mainjob class16_lastjob class16 class16_p class16p ownkid wicss3 wicss wpt1s weipts


* Set the variables that order the panel
sort idpers year
xtset idpers year

*RECODING*

keep if status==0
numlabel, add

*variable recoding

*recode civil status // widowers are excluded
recode civsta (1=0 "single") (2=1 "married/partnership") (3=2 "divorced/separated") (4=2) (5=.) (6=1) (7=2), gen(civsta_3)
tab civsta_3

*labour force participation // 
recode occupa (1 2=1 "employed") (.a .b .c=.) (else=0 "not employed"), gen(work)
tab work

*gender
recode sex(2=1 "female") (1=0 "male"), gen(female)
tab female

*educational categories
recode educat(-7/3=1)(4/6=2)(7/9=3) (10=4), gen(edu4)
label define edu4 ///
1 "Less than upper secondary education" /// primary education 
2 "Upper secondary education" /// apprenticeship, vocational school, bac/maturité
3 "Post-secondary/tertiary vocational" /// vocational post-secondary (Hochschule)
4 "University" // University
label values edu4 edu4
tab edu4

*religiosity
recode pr04 (6/9=1 "once a month or up") (1/5=0 "few times a year or less"), gen(reli)

*replace from previous waves if missing
tab reli year
gen reli_c=reli
bysort idpers (year) : replace reli_c=reli_c[_n-1] if missing(reli_c)

tab reli_c year

*party preference (if elections held today)

*Social-democratic party only
tab pp19
recode pp19 (3=1 "SP") (50 51 52=.) (else=0), gen(SP)
tab SP
// people who would not vote, vote for candidate not party, or for no party are set to missing

*Left party identification/preference excl. Greens
recode pp19 (3=1 "SP/PST") (9=1 "SP/PST") (50 51 52=.) (else=0), gen(left)

*Left party identification/preference incl. Greens
recode pp19 (3=1 "SP/PST/Greens") (9=1 "SP/PST/Greens") (11=1 "SP/PST/Greens") (50 51 52=.) (else=0), gen(left_gr)

tab1 SP left left_gr

*nationality
tab1 nat_1_ nat_2_ nat_3_
gen swiss=.
replace swiss=1 if nat_1_==8100 | nat_2_==8100 | nat_3_==8100
replace swiss=0 if (nat_1_!=8100 & nat_1_<.) | (nat_2_!=8100 & nat_2_<.) | (nat_3_!=8100 & nat_3_<.)
tab swiss

*kids // people with more than 9 kids are excluded
tab ownkid
recode ownkid (0=0 "no kids") (1/9=1 "kids") (else=.), gen(kids)
tab kids


* Generations of respondents
tab birthy
recode birthy (1933/1964=3) (1965/1980=4) (1981/2001=5), gen(cohort)
// "Baby boomers 1946-1964" ///
// "Gen X 1965-1980" ///
//"Millennials 1981-1996"
 
label define cohort ///
3 "Baby boomers and older" ///
4 "Gen X" ///
5 "Millennials and younger"
label values cohort cohort
tab cohort


*part-time and full-time work vs. everything else
tab occupa
recode occupa (1 = 1 "fulltime employed") (.a .b .c=.) (else=0 "parttime/not employed"), gen(ftwork)

recode occupa (2 = 1 "parttime employed") (.a .b .c=.) (else=0 "fulltime/not employed"), gen(ptwork)

*3 categories: part-time, full-time, not working (housework+unemployed), vs. everything else
recode occupa (1 = 1 "FT employed") (2 = 2 "PT employed") (7 10 = 3 "econ inactive") (.a .b .c=.) (else=0 "other"), gen(work3)

tab1 work work3 ftwork ptwork


/*transitions:

1. EDUCATION
*a. obtaining a post-secondary vocational degree
*b. obtaining a university degree

2. EMPLOYMENT
* a. employed —> economic inactivity/housework
* b. full-time work -> part-time work
* c. part-time work —> full-time work
* d. economic inactivity/housework -> employed
* e. education -> employed 

4. CIVIL STATUS
*a. unmarried -> married/reg. partnership
*b. married/reg. partnership -> divorced/separated

==> these transitions will overlap for some people, e.g. students working part-time

*/

*Count number of waves per person

* Generate an identifier for the first time an individual was included in the sample and one for the last time
sort idpers year
bysort idpers: gen total= _N
bysort idpers: gen num_wave= _n
gen last_obs= total==num_wave

by idpers, sort: gen nfirst= _n==1
count if nfirst
by idpers, sort: gen nlast= _n==_N
count if nlast


tab nfirst nlast

tab nfirst if nfirst==1 & nlast==1

*1. EDUCATIONAL transitions

*obtaining upper secondary degree
capture drop first_edu2 //[first observation of this level of education]
bysort idpers (year): gen first_edu2 = (edu4[_n-1]<2 & edu4==2)

*identify wave number in which obtained the degree:
capture drop edu2_fw // [first wave after transition]
by idpers (year): gen edu2_fw=num_wave if first_edu2==1

*impute this wave number for all person-years
capture drop wave_edu2
by idpers (year): egen wave_edu2=max(edu2_fw) 

*define transition variable for wave of transition + those after
capture drop edu2_trans
gen edu2_trans=0

*keep 1 after the transition
bysort idpers (year): replace edu2_trans=1 if edu4==2 & num_wave>=wave_edu2

label var edu2_trans "got upper sec degree"
xttab edu2_trans

*a. obtaining a post-secondary vocational degree
capture drop first_edu3 //[first observation of this level of education]
bysort idpers (year): gen first_edu3 = (edu4[_n-1]<3 & edu4==3)

*identify wave number in which obtained the degree:
capture drop edu3_fw // [first wave after transition]
by idpers (year): gen edu3_fw=num_wave if first_edu3==1

*impute this wave number for all person-years
capture drop wave_edu3
by idpers (year): egen wave_edu3=max(edu3_fw) 

*define transition variable for wave of transition + those after
capture drop edu3_trans
gen edu3_trans=0

bysort idpers (year): replace edu3_trans=1 if edu4==3 & num_wave>=wave_edu3

label var edu3_trans "got vocat post-sec degree"
xttab edu3_trans 

*b. obtaining a university degree
capture drop first_edu4 //[first observation of this level of education]
bysort idpers (year): gen first_edu4 = (edu4[_n-1]<4 & edu4==4)

*identify wave number in which obtained the degree:
capture drop edu4_fw // [first wave after transition]
by idpers (year): gen edu4_fw=num_wave if first_edu4==1

*impute this wave number for all person-years
capture drop wave_edu4
by idpers (year): egen wave_edu4=max(edu4_fw) 

*define transition variable for wave of transition + those after
capture drop edu4_trans
gen edu4_trans=0

bysort idpers (year): replace edu4_trans=1 if edu4==4 & num_wave>=wave_edu4

label var edu4_trans "got uni degree"
xttab edu4_trans 

*2. LABOUR MARKET/WORK transitions
* a. work —> economic inactivity/housework
* b. full-time work -> part-time work
* c. part-time work —> full-time work
* d. economic inactivity/housework (unemployed + man/woman at home) -> work
* e. education -> work

*a. work —> economic inactivity/housework (unemployed + man/woman at home)

capture drop first_wrk1 //[first observation after making this work/employment transition]
bysort idpers (year): gen first_wrk1 = (work[_n-1]==1 & work3==3) // first work, then econ inactive

*identify wave number in which made the transition:
capture drop wrk1_fw // [first wave after transition]
by idpers (year): gen wrk1_fw=num_wave if first_wrk1==1

*impute this wave number for all person-years
capture drop wave_wrk1
by idpers (year): egen wave_wrk1=max(wrk1_fw) 

*define transition variable for wave of transition + those after
capture drop wrk1_trans
gen wrk1_trans=0

bysort idpers (year): replace wrk1_trans=1 if work3==3 & num_wave>=wave_wrk1

label var wrk1_trans "work to econ inactive"
xttab wrk1_trans 

*b. full-time work -> part-time work

capture drop first_wrk2 //[first observation after making this work/employment transition]
bysort idpers (year): gen first_wrk2 = (work3[_n-1]==1 & work3==2) // first FT work, then PT work

*identify wave number in which made the transition:
capture drop wrk2_fw // [first wave after transition]
by idpers (year): gen wrk2_fw=num_wave if first_wrk2==1

*impute this wave number for all person-years
capture drop wave_wrk2
by idpers (year): egen wave_wrk2=max(wrk2_fw) 

*define transition variable for wave of transition + those after
capture drop wrk2_trans
gen wrk2_trans=0

bysort idpers (year): replace wrk2_trans=1 if work3==2 & num_wave>=wave_wrk2

label var wrk2_trans "FT to PT work"
xttab wrk2_trans

*c. part-time work —> full-time work

capture drop first_wrk3 //[first observation after making this work/employment transition]
bysort idpers (year): gen first_wrk3 = (work3[_n-1]==2 & work3==1) // first PT work, then FT work

*identify wave number in which made the transition:
capture drop wrk3_fw // [first wave after transition]
by idpers (year): gen wrk3_fw=num_wave if first_wrk3==1

*impute this wave number for all person-years
capture drop wave_wrk3
by idpers (year): egen wave_wrk3=max(wrk3_fw) 

*define transition variable for wave of transition + those after
capture drop wrk3_trans
gen wrk3_trans=0

bysort idpers (year): replace wrk3_trans=1 if work3==1 & num_wave>=wave_wrk3

label var wrk3_trans "PT to FT work"
xttab wrk3_trans

*d. economic inactivity/housework (unemployed + man/woman at home) -> work
capture drop first_wrk4 //[first observation after making this work/employment transition]
bysort idpers (year): gen first_wrk4 = (work3[_n-1]==3 & occupa[_n-1]!=4 & work==1) // first econ inactive (NOT in education), then work

*identify wave number in which made the transition:
capture drop wrk4_fw // [first wave after transition]
by idpers (year): gen wrk4_fw=num_wave if first_wrk4==1

*impute this wave number for all person-years
capture drop wave_wrk4
by idpers (year): egen wave_wrk4=max(wrk4_fw) 

*define transition variable for wave of transition + those after
capture drop wrk4_trans
gen wrk4_trans=0

bysort idpers (year): replace wrk4_trans=1 if work==1 & num_wave>=wave_wrk4

label var wrk4_trans "econ inactive to work"
xttab wrk4_trans 

*e. education -> employed
capture drop first_lb //[first observation in the labour market after being in education]
bysort idpers (year): gen first_lb = (occupa[_n-1]==4 & work==1)

*identify wave number in which obtained the degree:
capture drop lb_fw // [first wave after transition]
by idpers (year): gen lb_fw=num_wave if first_lb==1

*impute this wave number for all person-years
capture drop wave_lb
by idpers (year): egen wave_lb=max(lb_fw) 

*define transition variable for wave of transition + those after
capture drop wrk5_trans
gen wrk5_trans=0

bysort idpers (year): replace wrk5_trans=1 if work==1 & num_wave>=wave_lb

label var wrk5_trans "edu to work"
xttab wrk5_trans 


*3. CIVIL STATUS

*a. unmarried to married
capture drop first_civ1 //[first observation after making this transition]
bysort idpers (year): gen first_civ1 = (civsta_3[_n-1]==0 & civsta_3==1) // first unmarried, then married/reg part

*identify wave number in which made the transition:
capture drop civ1_fw // [first wave after transition]
by idpers (year): gen civ1_fw=num_wave if first_civ1==1

*impute this wave number for all person-years
capture drop wave_civ1
by idpers (year): egen wave_civ1=max(civ1_fw) 

*define transition variable for wave of transition + those after
capture drop civ1_trans
gen civ1_trans=0

bysort idpers (year): replace civ1_trans=1 if civsta_3==1 & num_wave>=wave_civ1

label var civ1_trans "unmarried to married/reg partnership"
xttab civ1_trans



*b. married to divorced/separated
capture drop first_civ2 //[first observation after making this transition]
bysort idpers (year): gen first_civ2 = (civsta_3[_n-1]==1 & civsta_3==2) // first married, then divorced/separated

*identify wave number in which made the transition:
capture drop civ2_fw // [first wave after transition]
by idpers (year): gen civ2_fw=num_wave if first_civ2==1

*impute this wave number for all person-years
capture drop wave_civ2
by idpers (year): egen wave_civ2=max(civ2_fw) 

*define transition variable for wave of transition + those after
capture drop civ2_trans
gen civ2_trans=0

bysort idpers (year): replace civ2_trans=1 if civsta_3==2 & num_wave>=wave_civ2

label var civ2_trans "married/partnership to divorced/separated"
xttab civ2_trans 



*ANALYSIS*

set scheme cleanplots
numlabel, add

*analytic sample

* Define analytic sample: all Swiss respondents under age 67 but older than 17 (voting age)
capture drop sample
gen sample=0
replace sample=1 if age>17 & age<67 & swiss==1

keep if sample==1


*MODELS*


*1. baseline model (Table S1)

xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
outreg2 using "${output}/SHP_baseline.xls", replace ctitle(left_gr FE) label

*add BE effects for comparison
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, be
outreg2 using "${output}/SHP_baseline.xls", append ctitle(left_gr BE) label

*replicate without the Greens (Table S3)
xtreg left i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
outreg2 using "${output}/SHP_baseline.xls", append ctitle(left FE) label

*add BE effects for comparison
xtreg left i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, be
outreg2 using "${output}/SHP_baseline.xls", append ctitle(left BE) label


//robustness check: without adding year dummies, but including age (Table S5)
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids age, fe vce(cluster idpers)
outreg2 using "${output}/SHP_baseline.xls", append ctitle(left_gr FE 2) label

*add BE effects for comparison
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids age, be
outreg2 using "${output}/SHP_baseline.xls", append ctitle(left_gr BE 2) label

//robustness check: including year dummies, and including cohort. only for BE (Table S5)
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.cohort i.year, be
outreg2 using "${output}/SHP_baseline.xls", append ctitle(cohort BE) label


*2. TRANSITION ANALYSIS 

//use analytic sample of baseline models
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
capture drop sample_trans
gen sample_trans=1 if e(sample)

//Table S2
xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.year, fe vce(cluster idpers), if female==1 & sample_trans==1
outreg2 using "${output}/SHP_transitions.xls", replace ctitle(left_gr women) label

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.year, fe vce(cluster idpers), if female==0 & sample_trans==1
outreg2 using "${output}/SHP_transitions.xls", append ctitle(left_gr men) label

// replicate without year dummies but controlling for age: (Table S6)
xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids age, fe vce(cluster idpers), if female==1 & sample_trans==1
outreg2 using "${output}/SHP_transitions.xls", append ctitle(left_gr women 2) label


xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans   i.reli_c i.kids age, fe vce(cluster idpers), if female==0 & sample_trans==1
outreg2 using "${output}/SHP_transitions.xls", append ctitle(left_gr men 2) label


*replicate without the Greens (Table S4)
xtreg left civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids i.year, fe vce(cluster idpers), if female==1 & sample_trans==1
outreg2 using "${output}/SHP_transitions.xls", append ctitle(left women) label

xtreg left civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids i.year, fe vce(cluster idpers), if female==0 & sample_trans==1
outreg2 using "${output}/SHP_transitions.xls", append ctitle(left men) label


//Table 1
*compute frequencies of transitions in our analytic sample [how many people we observe undergo this]
xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans wrk5_trans i.reli_c i.kids i.year, fe vce(cluster idpers), if sample_trans==1

xttab first_civ1  if e(sample)
xttab first_civ2  if e(sample)
xttab first_edu2  if e(sample)
xttab first_edu3  if e(sample)
xttab first_edu4  if e(sample)
xttab first_wrk1  if e(sample)
xttab first_wrk2  if e(sample)
xttab first_wrk3  if e(sample)
xttab first_wrk4  if e(sample)
xttab first_lb  if e(sample)


***REPLICATE RESULTS WITHOUT RW POPULIST PARTIES IN THE REFERENCE CATEGORY***

recode pp19 (3 9 11=1 "SP/PST/Greens") (4 15=.) (50 51 52=.) (else=0), gen(left_exprp)
tab1 pp19 left_exprp,m
//SVP and Lega dei Ticinesi now set to missing instead of 0

*1. BASELINE MODELS (Table S7)

xtreg left_exprp i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
outreg2 using "${output}/SHP_appendix_PRP_1.xls", replace ctitle(PRP FE) label

*add BE effects for comparison
xtreg left_exprp i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, be
outreg2 using "${output}/SHP_appendix_PRP_1.xls", append ctitle(PRP BE) label


*2. TRANSITION ANALYSIS (Table S8)
xtreg left_exprp i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
capture drop sample_trans
gen sample_trans=1 if e(sample) 

xtreg left_exprp civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.year, fe vce(cluster idpers), if female==1 & sample_trans==1
outreg2 using "${output}/SHP_appendix_PRP_2.xls", replace ctitle(PRP women) label



xtreg left_exprp civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.year, fe vce(cluster idpers), if female==0 & sample_trans==1
outreg2 using "${output}/SHP_appendix_PRP_2.xls", append ctitle(PRP men) label





*DESCRIPTIVES*
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, be
ttest left_gr, by(female), if e(sample)
// gender gap of .062

ttest left, by(female), if e(sample)
// gender gap of .04

ttest pp10, by(female), if e(sample) 
// gender gap in LR self-placement is 0.7

xtreg left_gr female##year, re, if e(sample)
margins, dydx(female) at(year=(1999(1)2019)) post coeflegend
est store gendergap

coefplot (gendergap, label(Difference between men and women))||, ///
vertical recast(scatter) ///
rename(1._at=1999 2._at=2000 3._at=2001 4._at=2002 5._at=2003 6._at=2004 7._at=2005 8._at=2006 9._at=2007 ///
10._at=2008 11._at=2009 12._at=2010 13._at=2011 14._at=2012 15._at=2013 16._at=2014 17._at=2015 18._at=2016 ///
19._at=2017 20._at=2018 21._at=2019) ///
xlabel(, angle(45)) xscale(lstyle(none)) ytitle("Probability of supporting LW party") yscale(lstyle(none)) ///
byopts(legend(position(6))) plotregion(lcolor(gs10) lwidth(small)) yline(0) ///
yscale (range (-.02 .1)) ylabel(-.02 (.02) .1) yline(0) ///
title("Switzerland: gender gap in voting", margin(medium)) legend(cols(2) position(6))
graph save "${output}/CH_gendergap_marginsdydx.gph", replace
graph export "${output}/CH_gendergap_marginsdydx.jpg", replace

